<?
require(PATH_CLASS."model.php");
class Form extends Model{	
	
	public function setFieldSet(){
		
		$fieldSet =  array(
							"register"=>"ลงทะเบียนสมาชิกใหม่",
							"bb1"=>"กำปั้นกับไม้มาลัยค้ำจุล"
						);

		parent::setModelFieldSet($fieldSet);
	}
	
	public function setButtonControlInput(){
		$arrayButton = array(
							"btn_save"=>array(
												"บันทึกข้อมูล",
												"submit"
											),
							/*"btn_close"=>array(
												"ออก",
												"button",
												"loadTab(".$this->tab.",'testModel','view')"
											)*/
							);
		parent::setModelButtonControlInput($arrayButton);
	}
	
	public function setButtonControlOutput(){
		$arrayButton = array("btn_edit"=>array("แก้ไขข้อมูล","button","loadTab(".$this->tab.",'testModel','form')"));
		parent::setModelButtonControlOutput($arrayButton);
	}
	
	public function setInput(){
		$query = "select * from member_tb where member_id='".$_POST["member_id"]."'";
		$arrayResult = Database::fetchArray(Database::query($query));
		$arrayInput["label"] = 'เพศ';
		$arrayInput["labelWidth"] = 15;
		$arrayInput["input"] = '<input type="radio" name="member_titlename" id="member_titlename" value="ชาย" checked="">ชาย&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="member_titlename" id="member_titlename" value="หญิง">หญิง';
		$arrayInput["inputWidth"] = 85;
		$arrayInput["required"] = true;
		$Input["register"][] = $arrayInput;
		
		$arrayInput["label"] = 'ชื่อ-นามสกุล';
		$arrayInput["labelWidth"] = 15;
		$arrayInput["input"] = '<input type="text" class="span6 typeahead" name="member_name" id="member_name" value="'.$arrayResult["member_name"].'"/>';
		$arrayInput["inputWidth"] = 85;
		$arrayInput["required"] = true;
		$Input["register"][] = $arrayInput;
		
		$arrayInput["label"] = 'บัตรประชาชน';
		$arrayInput["labelWidth"] = 15;
		$arrayInput["input"] = '<input type="text" class="span6 typeahead" name="member_cardid" id="member_cardid" value="'.$arrayResult["member_cardid"].'"/>';
		$arrayInput["inputWidth"] = 85;
		$arrayInput["required"] = true;
		$Input["register"][] = $arrayInput;
		
		$arrayInput["label"] = 'ที่อยู่';
		$arrayInput["labelWidth"] = 15;
		$arrayInput["input"] = '<input type="text" class="span6 typeahead" name="member_address" id="member_address" value="'.$arrayResult["member_address"].'"/>';
		$arrayInput["inputWidth"] = 85;
		$arrayInput["required"] = true;
		$Input["register"][] = $arrayInput;
		
		$arrayInput["label"] = 'เบอร์โทร';
		$arrayInput["labelWidth"] = 15;
		$arrayInput["input"] = '<input type="text" class="span6 typeahead" name="member_tel" id="member_tel" value="'.$arrayResult["member_tel"].'"/>';
		$arrayInput["inputWidth"] = 85;
		$arrayInput["required"] = true;
		$Input["register"][] = $arrayInput;
		
		$arrayInput["label"] = 'ค่าสมัครสมาชิก';
		$arrayInput["labelWidth"] = 15;
		$arrayInput["input"] = '<input type="text" class="span6 typeahead" name="income_money" id="income_money" value="'.$arrayResult["income_money"].'"/>';
		$arrayInput["inputWidth"] = 85;
		$arrayInput["required"] = true;
		$Input["register"][] = $arrayInput;
				
		parent::setModelInput($Input);
	}

	public function setValidate(){
	
		/*if($_POST["aaa"]==""){
			parent::$checkValidate["aaa"][] = "ต้องการค่า";
		}
		if($_POST["aaa1"]==""){
			parent::$checkValidate["aaa1"][] = "ต้องการค่า";
		}*/
	}

	public function setOutput(){
		$query = "select * from member_tb where member_id='".$_POST["member_id"]."'";
		$arrayResult = Database::fetchArray(Database::query($query));
		
		$arrayOutput["label"] = 'รหัส';
		$arrayOutput["labelWidth"] = 15;
		$arrayOutput["output"] = $arrayResult["about_id"];
		$arrayOutput["inputWidth"] = 85;
		$Output["NONE"][] = $arrayOutput;

		$arrayOutput["label"] = 'ชื่อ';
		$arrayOutput["labelWidth"] = 15;
		$arrayOutput["output"] = $arrayResult["about_name"];
		$arrayOutput["outputWidth"] = 85;
		$Output["NONE"][] = $arrayOutput;	

		parent::setModelOutput($Output);
	}

	public function insertData(){
		$today = date("Y-m-d H:i:s"); 
		$member_id = Database::getLastValue('member_tb','member_id')+1;
		$arrayInsertData = array("member_id"=>$member_id,
								"member_titlename"=>$_POST["member_titlename"],
								"member_name"=>$_POST["member_name"],
								"member_cardid"=>$_POST["member_cardid"],
								"member_address"=>$_POST["member_address"],
								"member_tel"=>$_POST["member_tel"],
								"member_date"=>$today,
								"member_ena"=>'1',
								);
		$query = Database::getInsertData($arrayInsertData,"member_tb");
		//echo $query = Database::getUpdateData($arrayInsertData,"about","about_id=4");
		Database::query($query);
		$income_id = Database::getLastValue('income_tb','income_id')+1;
		$arrayInsertData = array("income_id"=>$income_id,
								"income_type"=>'1',
								"income_money"=>$_POST["income_money"],
								"income_date"=>$today,
								"income_rent_id"=>'0',
								);
		$query = Database::getInsertData($arrayInsertData,"income_tb");
		//echo $query = Database::getUpdateData($arrayInsertData,"about","about_id=4");
		Database::query($query);
	}
}
?>
